package cn.ywang.deep;

import java.io.*;

/**
 * @Auther: BeatificWang
 * @Date: 2018/9/24 8:48
 */
public class Car implements Cloneable, Serializable {

	public String name = "";

	public Engine engine = new Engine();

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Engine getEngine() {
		return this.engine;
	}

	public void setEngine(Engine engine) {
		this.engine = engine;
	}

	@Override
	public Car clone() {
		Car car = null;
		try {
			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
			// 对象序列化
			ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
			objectOutputStream.writeObject(this);

			// 反序列化
			ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
			ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
			car = (Car) objectInputStream.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return car;
	}
}
